<include file="public@head"/>
</head>

<body>
<div class="layui-fluid wrap js-check-wrap" id="component-tabs">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">文章分类</div>
                <div class="layui-card-body">
                    <form method="post" class="layui-form js-ajax-form" action="{:url('AdminCategory/listorders')}">
                        <table lay-filter="demo" lay-data="{id: 'idDemo'}">
                            <thead>
                            <tr>
                                <th lay-data="{checkbox:true}">
                                    <input disabled type="checkbox" lay-skin="primary" lay-filter="js-check-all"
                                           class="js-check-all" data-direction="x" data-checklist="js-check-x">
                                </th>
                                <th lay-data="{field:'id', width:150}">ID</th>
                                <th lay-data="{field:'name'}">分类名称</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!-- <foreach name="categories" item="vo">
                                <tr>
                                    <td>
                                        <php>$checked = in_array($vo['id'],$selectedIds)?'checked':'';</php>
                                        <input type="checkbox" class="js-check" lay-skin="primary" lay-filter="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" value="{$vo.id}" data-name="{$vo.name}" {$checked}>
                                    </td>
                                    <td>{$vo.id}</td>
                                    <td>{$vo.name}</td>
                                    <td>{$vo.description}</td>
                                </tr>
                            </foreach> -->
                            {$categories_tree}
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<include file="public@footer"/>
<script>
    layui.define(['form', 'table'], function (exports) {
        var form = layui.form,
            table = layui.table;
        table.init('demo', {
            limit: 10
        });
        function confirm() {
            var selectedCategoriesId = [];
            var selectedCategoriesName = [];
            var selectedCategories = [];


            let checkStatus = table.checkStatus('idDemo');
            for (let i in checkStatus.data) {
                let name = checkStatus.data[i].name;

                let id = checkStatus.data[i].id
                let start = name.indexOf('>');
                let end = name.indexOf('<', start);

                selectedCategoriesId.push(id);
                selectedCategoriesName.push(name.slice(start + 1, end));

                selectedCategories.push({
                    id: id,
                    name: name.slice(start + 1, end)
                });
            }
            return {
                selectedCategories: selectedCategories,
                selectedCategoriesId: selectedCategoriesId,
                selectedCategoriesName: selectedCategoriesName
            };
        }


        var selectForm = {};
        selectForm.confirm = confirm;
        exports('selectForm', selectForm);
    });

</script>
</body>

</html>